package com.ala4.oxcafe.dto;

import com.ala4.oxcafe.common.utils.JSONUtil;
import com.ala4.oxcafe.common.utils.collection.CollUtil;
import com.ala4.oxcafe.common.utils.text.StrUtil;
import com.ala4.oxcafe.enums.OperateEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.List;

/**
 * 服务单审核DTO
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/15 14:39
 */
@Data
@Schema(description = "质保单审核DTO")
public class ServiceAuditDTO {

    @NotNull(message = "id不能为空")
    @Schema(description = "服务单ID")
    private Long id;

    @NotNull(message = "操作不能为空")
    @Schema(description = "审核通过/驳回", anyOf = {OperateEnum.class})
    private OperateEnum operate;

    @Schema(description = "审核意见")
    private String auditOpinions;

    @Schema(description = "质保单年限(单位:月)")
    private Integer warrantyPeriod;

    public String handleAuditComment(String auditComments) {
        List<AuditCommentDTO> auditCommentList = CollUtil.newArrayList();
        if (StrUtil.isNotEmpty(auditComments)) {
            auditCommentList = JSONUtil.toList(auditComments, AuditCommentDTO.class);
        }
        if (StrUtil.isNotEmpty(auditOpinions)) {
            auditCommentList.add(new AuditCommentDTO(auditOpinions));
        }
        return JSONUtil.toJsonStr(auditCommentList);
    }

}
